// pages/Complaints/Complaints.js
const common = require("../../utils/conmon.js");
var app = getApp();
Page({
  data:{
   
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },

  setUserName: function (e) {
    if (e.detail.value != "") {
      this.setData({
        setUserName:e.detail.value
      }) 
    }
  },
  onShareAppMessage: function (res) {
    return {
      title: '山野土菜馆',
      path: '/pages/homepage/homepage?id=' + wx.getStorageSync("userid"),
    }
  },
  setUserPhone: function (e) {
    this.setData({
        setUserPhone:e.detail.value
      }) 
  }, 


  setUserAdvice: function (e) {
    if (e.detail.value != "") {
      this.setData({
        setUserAdvice: e.detail.value
      })
    }
  },

  complaintsSubmit: function (e) {
  // console.log(this.data.setUserAdvice)  
    var that = this;
    wx.request({
      url: app.globalData.allUrl + "/orderFormAction/complaintOrderForm",
      data: {
        id: app.complaintProductId,
        complainContent: that.data.setUserAdvice,
        complainName: that.data.setUserName,
        complainPhone: that.data.setUserPhone
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        // success
        if (res.data) {
          if (res.data == "已投诉") {
            wx.showToast({
              title: '已投诉',
              icon: 'success',
              duration: 2000
            })
            setTimeout(function () {
              wx.navigateBack({
                delta: '1?id=5', // 回退前 delta(默认为1) 页面
                success: function (res) {
                  // success
                }
              })
            }, 2000)
          } else {
            wx.showToast({
              title: '提交成功',
              icon: 'success',
              duration: 2000
            })
            setTimeout(function () {
              wx.navigateBack({
                delta: 1, // 回退前 delta(默认为1) 页面
                success: function (res) {
                  // success
                  common.afterSale(that)
                }
              })
            }, 2000)

          }
        } else {
          wx.showToast({
            title: '提交失败',
            icon: 'success',
            duration: 2000
          })
        }
      },
      fail: function (res) {
        // fail
      },
      complete: function (res) {
        // complete
      }
    })

  }
})